package ginserver

import (
	"github.com/gin-gonic/gin"

	"jdfs2/internal/api"
)

// Run starts Gin HTTP server with SigV4 auth and S3-compatible routes.
func Run() error {
	gin.SetMode(gin.ReleaseMode)
	r := gin.New()
	r.Use(gin.Recovery())

	// Register all S3 API routes
	if err := api.RegisterRoutes(r); err != nil {
		return err
	}

	return r.Run(":8000")
}

// RunWithAddr starts Gin server on given address, e.g. "0.0.0.0:8000".
func RunWithAddr(addr string) error {
	gin.SetMode(gin.ReleaseMode)
	r := gin.New()
	r.Use(gin.Recovery())

	if err := api.RegisterRoutes(r); err != nil {
		return err
	}

	return r.Run(addr)
}
